package com.aaa.ssm.controller;

import com.aaa.ssm.entity.Factory;
import com.aaa.ssm.service.impl.FactoryServiceImpl;
import com.aaa.ssm.util.Page;
import com.aaa.ssm.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("factory")
public class FactoryController extends BaseController{
    @Resource
    private FactoryServiceImpl factoryService;

    //根据参数查询
    @PostMapping("queryByPage")
    //@ResponseBody
    public Result queryByPage(@RequestBody Page<Factory> page){
        return success(factoryService.queryByPage(page));
    }

    //@RequestMapping(value="queryByParam",method={RequestMethod.GET})
    @PostMapping("queryByParam")
    //@ResponseBody//返回的deptList集合转换JSON
    public Result queryByParam(@RequestBody Factory factory) {
        List<Factory> factoryList = factoryService.queryByParam(factory);
        return success(factoryList);
        //return new Result<>(ResultStatus.SUCCESS.getReturnCode(),"查询成功",deptList);
    }
    @GetMapping("queryById")
    //@ResponseBody
    public Result queryById(Integer factoryId){
        //魔法值不同的开发人员会写不同的魔法值，所以要统一
        //return new Result<>(2000,"查询成功1",deptService.queryById(deptNo));
        //没封装之前的返回
        //return new Result<>(ResultStatus.SUCCESS.getReturnCode(),"查询成功",deptNo);
        //封装之后的返回，两个都可以用
        return success(factoryService.queryById(factoryId));
    }

    @PutMapping("add")
    private Result add(@RequestBody Factory factory){
        return success(factoryService.add(factory));
    }

    @PutMapping("update")
    //@ResponseBody
    private Result update(@RequestBody Factory factory){
        return success(factoryService.update(factory));
    }

    @DeleteMapping("delete")
    //@ResponseBody
    private Result delete(Integer factoryId){
        return success(factoryService.delete(factoryId));
    }
}
